<template>
    <div class="bg-primary-300 text-white min-h-screen pt-12">
        <div class="text-center text-2xl p-8">
            激活你的账号
        </div>
        <div class="flex items-center justify-center">
            <div class="w-1/4 p-4 bg-gray-100 rounded-lg shadow-lg">
                <div class="text-black text-center p-4">
                    请点击下方按钮，激活账号
                </div>
                <div class="flex justify-center">
                    <button v-on:click="activate" class="bg-green-500 text-white px-4 py-2 rounded">激活账号</button> 
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { activateUser } from '@/api/account' // 从 account.js 中导入
import { showToast } from '@/utils/toast'

const route = useRoute()
const loading = ref(false)

const activate = async () => {
  const uid = route.params.uid
  const token = route.params.token

  if (!uid || !token) {
    showToast('激活链接无效', 'error')
    return
  }

  try {
    loading.value = true
    const response = await activateUser({
      uid,
      token
    })
    showToast('账号激活成功', 'success')
  } catch (error) {
    console.error('激活失败:', error)
    showToast('激活失败，请检查链接或稍后重试', 'error')
  } finally {
    loading.value = false
  }
}

</script>

